package com.bank.common.util;

import cn.hutool.core.util.StrUtil;

/**
 * 类SqlUtil.java的实现描述：sql 处理工具类
 *
 * @author zach
 * @Date :2020-06-17 10:17.
 */
public class MySqlUtil {


    /**
     * 获取orderBy语句
     *
     * @param sort 转换前的驼峰式命名的字符串
     * @param asc
     * @return
     */
    public static String orderBy(String sort, Boolean asc) {
        if (StrUtil.isNotEmpty(sort)) {
            sort = StrUtil.toUnderlineCase(sort);
            if (asc) {
                return sort + " ASC";
            } else {
                return sort + " DESC";
            }
        }
        return null;
    }
    public static String orderByNotUnderlineCase(String sort, Boolean asc) {
        if (StrUtil.isNotEmpty(sort)) {
            if (asc) {
                return sort + " ASC";
            } else {
                return sort + " DESC";
            }
        }
        return null;
    }


    /**
     * 获取左like
     *
     * @param value
     * @return
     */
    public static String leftLike(String value) {
        if (StrUtil.isNotEmpty(value)) {
            return "%"+value;
        }
        return null;
    }

    public static String rightLike(String value) {
        if (StrUtil.isNotEmpty(value)) {
            return value+"%";
        }
        return null;
    }

    public static String allLike(String value) {
        if (StrUtil.isNotEmpty(value)) {
            return "%" + value + "%";
        }
        return null;
    }
}
